home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / gfx / show / Easy_MPEG105.lha / Easy_MPEG / Easy_MPEG.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-05  |  19KB  |  708 lines

  1. /* ******************* Easy_MPEG Version 1.04 *********************** */
  2. /* *******************    Scott A. Tribbey    *********************** */
  3. /* *******************      March 3,1995      *********************** */
  4.  
  5. /* Painless MPEG! Yup this should make it easy for anybody */
  6. /* to create their own MPEG movies */
  7.  
  8. /* AREXX script for making MPEG-1 video streams using */
  9. /* the Berkley University MPEG-1 encoder for the Amiga */
  10. /* This macro will create the MPEG-1 stream from 24bit frames */
  11. /* that have been or are being created by a ray tracer or */
  12. /* other graphics output program */
  13.  
  14. /* The program uses the MPEG-1 encoder to create individual GOPS */
  15. /* or 'Groups Of Pictures' as another application produces the frames */
  16. /* In this way, hard drive space is conserved, as everytime the */
  17. /* number of produced frames available is enough to encode a GOP */
  18. /* the frames will be converted to a GOP and deleted */
  19. /* This allows for very large animations to be constructed on a */
  20. /* system with only modest hard drive space */
  21.  
  22. /* TRACE('results') */
  23.  
  24.  
  25.  
  26.  
  27. IF ARG() = 1 THEN
  28.   DO
  29.  
  30.     IF EXISTS( 'MPEG.settings' ) THEN
  31.        DO
  32.           Call ReadParams()
  33.           GOPS_COMPLETE = 0   /* Just here to initialize variable */
  34.        END
  35.     ELSE
  36.        Call InitGlobals()
  37.  
  38.     PARSE ARG FrameName StFrame EndFrame Xdim Ydim OutFile FrmDelay DelOldFrms .
  39.  
  40.     IF FrameName == '?' THEN
  41.       DO
  42.         SAY 'Usage: rx Easy_MPEG Base_Frame_Name Start End Xdim Ydim '
  43.         SAY '                    OutFileName Delay DelOldFrames'
  44.         SAY
  45.         SAY 'Example: rx Make_MPEG dh0:IFF/Frame. 0000 0030 352 240 Movie 30 YES'
  46.         SAY '         creates Movie.mpg from:'
  47.         SAY '         dh0:IFF/Frame.0000 through dh0:IFF/Frame.0030'
  48.         SAY '         resolution is 352 by 240, directory scan every 30 sec.'
  49.         SAY '         original IFF files will be deleted'
  50.         SAY
  51.         EXIT    /* Quit here */
  52.       END
  53.  
  54.     Call GetFileInDir()
  55.     Call GetFrameName()
  56.     Call CalcGOPS()
  57.  
  58.   END
  59. ELSE
  60.   DO
  61.  
  62.     IF EXISTS( 'MPEG.settings' ) THEN
  63.      DO
  64.        Call ReadParams()
  65.        Call GetFileInDir()
  66.        Call CalcGOPS()
  67.        GOPS_COMPLETE = 0   /* Just here to initialize variable */
  68.        Call Stats()
  69.        Call RunHost()
  70.      END
  71.     ELSE
  72.      DO
  73.        Call InitGlobals()
  74.        Call CalcGOPS()
  75.        Call Stats()
  76.        Call RunHost()
  77.      END
  78.  
  79.   END
  80.  
  81. /* Save Parameters in the MPEG.settings file for future reference in case this session
  82.    gets interrupted */
  83.  
  84. Call SaveParams()
  85.  
  86. /* This first section is where the program checks to see if any of */
  87. /* the work is already done.  If any GOP's have been produced, then */
  88. /* the program starts from where it was last interrupted */
  89.  
  90. Error = 0
  91.  
  92. DO I = 0 to TOT_GOPS - 1 UNTIL Error = 1
  93.    IF ~ EXISTS(InputDir || OutFile || '.mpg' || '.gop.' || I)
  94.       THEN Error = 1
  95. END
  96.  
  97. GOPS_COMPLETE = I
  98.  
  99.  
  100. Call Stats()
  101.  
  102. Call WriteParamFile()
  103.  
  104.  
  105. /* change HOST address to AmigaDOS and set a decent size stack */
  106.  
  107. ADDRESS ('COMMAND')
  108. 'Stack 30000'
  109.  
  110.  
  111. /* Wait for and create individual GOPS as frames are available */
  112. /* This will run forever if it never gets all the appropriate frames */
  113. /* Pressing CTRL-C here will break the program */
  114.  
  115. /* Main loop where frames are scanned for */
  116.  
  117. DO UNTIL GOPS_COMPLETE == TOT_GOPS
  118.  
  119. SAY 'Waiting for Frames for GOP 'GOPS_COMPLETE
  120. SAY '***** PRESS CTRL-C TO ABORT *****'
  121.  
  122.  
  123. LastGOPFrm = StFrame + (GOPS_COMPLETE * GOP_SIZE) + GOP_SIZE
  124.  
  125. IF LastGOPFrm > EndFrame THEN
  126.    LastGOPFrm = EndFrame
  127.  
  128. /* Create ZERO padded frame number for file name */
  129. FrmNumber = RIGHT(LastGOPFrm,LENGTH(StFrame),0)
  130.  
  131. SAY 'Waiting for' FrameName || FrmNumber
  132. SAY ''
  133.  
  134. IF EXISTS( InputDir || FrameName || FrmNumber ) THEN
  135.     DO
  136.  
  137.         /* Check if this is the last frame of the animation */
  138.         /* if it is, then we must check it by using the OPEN() */
  139.         /* function to see if it is complete */
  140.         /* if it isn't then we BREAK out of this DO segment and */
  141.         /* wait again */
  142.  
  143.         IF FrmNumber == EndFrame THEN
  144.           IF OPEN( TESTF , InputDir || FrameName || FrmNumber ) THEN
  145.             DO
  146.                BOGUS = CLOSE( TESTF )
  147.                IF ((TOT_FRAMES // GOP_SIZE) > 0) & ,
  148.                    (GOPS_COMPLETE = TOT_GOPS - 1) THEN
  149.                   DO
  150.                     GOP_SIZE = TOT_FRAMES // GOP_SIZE
  151.                     LastGOPFrm = LastGOPFrm + 1
  152.                   END
  153.                ELSE IF ((TOT_FRAMES // GOP_SIZE) == 0) & ,
  154.                        (GOPS_COMPLETE = TOT_GOPS - 1) THEN
  155.                        LastGOPFrm = LastGOPFrm + 1
  156.             END
  157.           ELSE
  158.             BREAK
  159.  
  160.  
  161.  
  162.         /* First turn IFF-24 frames into .PPM files */
  163.         /* and delete the original IFF-24 frames if requested */
  164.  
  165.         DO x = (LastGOPFrm - GOP_SIZE) to (LastGOPFrm - 1)
  166.            FrmNumber = RIGHT( x ,LENGTH(StFrame),0)
  167.            SAY 'Converting Frame'FrmNumber'to PPM format'
  168.  
  169.            RC = 0
  170.            '24toPPM >NIL:' InputDir || FrameName || FrmNumber ,
  171.                      InputDir || FrameName || FrmNumber || '.ppm'
  172.  
  173.            /* Check to see if 24toppm failed due to wrong number */
  174.            /* of bitplanes and use ilbmtoppm instead */
  175.  
  176.            IF RC == 20 THEN
  177.              'ILBMtoPPM  <'InputDir || FrameName || FrmNumber ,
  178.                          '>'||InputDir || FrameName || FrmNumber || '.ppm'
  179.  
  180.            IF DelOldFrms == 'YES' THEN
  181.              'delete' InputDir || FrameName || FrmNumber
  182.         END
  183.  
  184.       'mpeg_encode -gop' GOPS_COMPLETE OutFile||'.param'
  185.  
  186.       GOPS_COMPLETE = GOPS_COMPLETE + 1
  187.  
  188.       /* Now Delete the PPM files */
  189.  
  190.       DO x = (LastGOPFrm - GOP_SIZE) to (LastGOPFrm - 1)
  191.          FrmNumber = RIGHT( x ,LENGTH(StFrame),0)
  192.          'delete' InputDir || FrameName || FrmNumber || '.ppm'
  193.       END
  194.  
  195.       Call Stats()
  196.  
  197.     END
  198.  
  199.  
  200. IF GOPS_COMPLETE == TOT_GOPS THEN
  201.    BREAK
  202.  
  203. /* Put in a frame search delay so as not to absorb processor time */
  204.  
  205. Call delay( FrmDelay * 50 )
  206.  
  207. /* ADDRESS COMMAND 'wait' FrmDelay   THIS USED TOO MUCH CPU TIME */
  208.  
  209. END
  210.  
  211.  
  212.  
  213.  
  214. /* Now that all graphic files are done generating */
  215. /* combine all the GOPS into an MPEG file */
  216.  
  217.  
  218. /* Here is where we give the final command to mpeg_encode */
  219. /* which then combines the GOP's into a full MPEG-1 file */
  220.  
  221.  
  222. 'mpeg_encode -combine_gops' OutFile||'.param'
  223.  
  224. /* Now Delete the GOPS and we're done! */
  225. DO I = 0 to (TOT_GOPS - 1)
  226.   'delete' InputDir || OutFile || '.mpg' || '.gop.' || I
  227. END
  228.  
  229.  
  230. SAY '------------------------------'
  231. SAY '    Processing Complete!'
  232. SAY '------------------------------'
  233.  
  234. SAY
  235.  
  236.  
  237. /* Here is where the last little OK window pops up */
  238. /* if you don't like that, then just comment the following */
  239. /* line out of the program */
  240.  
  241. Call Request(300,100,"Processing Complete",,"OK",,)
  242.  
  243. EXIT
  244.  
  245.  
  246.  
  247.  
  248. /* ================================================================== */
  249. /* This is where the functions are defined */
  250. /* ================================================================== */
  251.  
  252.  
  253. /* This separates the FrameName and InputDir from the input string */
  254.  
  255. GetFrameName:
  256.  
  257.     IF LASTPOS('/' , FrameName ) > 0 THEN
  258.       DO
  259.         FileInDir = LEFT( FrameName, LASTPOS('/' , FrameName )-1 )
  260.         InputDir = LEFT( FrameName, LASTPOS('/' , FrameName ) )
  261.         FrameName = SUBSTR( FrameName, LASTPOS('/' , FrameName )+1 )
  262.       END
  263.     ELSE
  264.         InputDir = ''
  265.  
  266. RETURN 0
  267.  
  268.  
  269.  
  270. GetFileInDir:
  271.  
  272.     IF LASTPOS('/' , InputDir ) > 0 THEN
  273.         FileInDir = LEFT( InputDir, LASTPOS('/' , InputDir )-1 )
  274.     ELSE
  275.         FileInDir = ''
  276.  
  277. RETURN 0
  278.  
  279.  
  280.  
  281. /* This initializes the global variables in case there */
  282. /* is no MPEG.settings file to read them from */
  283.  
  284. InitGlobals:
  285.  
  286.     FrameName = 'Pic.'
  287.     StFrame = '0000'
  288.     EndFrame = '0030'
  289.     Xdim = 160
  290.     Ydim = 120
  291.     InputDir = 'input/'
  292.     FileInDir = 'input'
  293.     PATTERN = 'IPBP'
  294.     IQScale = 2
  295.     PQScale = 4
  296.     BQScale = 6
  297.     FrmDelay = 60
  298.     DelOldFrms = 'YES'
  299.     OutFile = 'Movie'
  300.  
  301.     GOPS_COMPLETE = 0
  302.  
  303. RETURN 0
  304.  
  305.  
  306.  
  307. /* This prints the Status to the CON: window */
  308.  
  309. Stats:
  310.     SAY ' '  /* This is a clear screen character */
  311.     SAY 'Easy_MPEG  Scott Tribbey 1995  All rights reserved'
  312.     SAY 'MPEG Stream Status'
  313.     SAY '--------------------------------------------------'
  314.     SAY 'Start Frame  :' FrameName || StFrame
  315.     SAY 'End Frame    :' FrameName || EndFrame
  316.     SAY 'Frame Width  :' Xdim
  317.     SAY 'Frame Height :' Ydim
  318.     SAY 'Input Dir.   :' InputDir
  319.     SAY 'Encode Patt. :' PATTERN
  320.     SAY 'IQScale      :' IQScale
  321.     SAY 'PQScale      :' PQScale
  322.     SAY 'BQScale      :' BQScale
  323.     SAY 'GOP_SIZE     :' GOP_SIZE
  324.     SAY 'Total Frames :' TOT_FRAMES
  325.     SAY 'Dir. Scan    :' FrmDelay 'sec.'
  326.     SAY 'Del Old Frms :' DelOldFrms
  327.     SAY 'Total GOPS   :' TOT_GOPS
  328.     SAY 'OutFile Name :' OutFile || '.mpg'
  329.     SAY '--------------------------------------------------'
  330.     SAY 'GOPS Complete:' GOPS_COMPLETE '(' (GOPS_COMPLETE / TOT_GOPS * 100) '% )'
  331.     SAY '--------------------------------------------------'
  332.     SAY
  333.     SAY
  334.  
  335. RETURN 0
  336.  
  337.  
  338. /* Store current MPEG parameters in MPEG.settings file */
  339.  
  340. SaveParams:
  341.  
  342.     OPEN( SETFILE,'MPEG.settings', 'W' )
  343.  
  344.     WRITELN( SETFILE , FrameName )
  345.     WRITELN( SETFILE , InputDir )
  346.     WRITELN( SETFILE , StFrame )
  347.     WRITELN( SETFILE , EndFrame )
  348.     WRITELN( SETFILE , Xdim )
  349.     WRITELN( SETFILE , Ydim )
  350.     WRITELN( SETFILE , OutFile )
  351.     WRITELN( SETFILE , FrmDelay )
  352.     WRITELN( SETFILE , DelOldFrms )
  353.     WRITELN( SETFILE , IQScale )
  354.     WRITELN( SETFILE , PQScale )
  355.     WRITELN( SETFILE , BQScale )
  356.     WRITELN( SETFILE , PATTERN )
  357.  
  358.     CLOSE( SETFILE )
  359.  
  360. RETURN 0
  361.  
  362.  
  363. /* Read MPEG parameters from MPEG.settings file */
  364.  
  365. ReadParams:
  366.  
  367.     OPEN( SETFILE,'MPEG.settings', 'R' )
  368.  
  369.     FrameName = READLN( SETFILE )
  370.     InputDir = READLN( SETFILE )
  371.     StFrame = READLN( SETFILE )
  372.     EndFrame = READLN( SETFILE )
  373.     Xdim = READLN( SETFILE )
  374.     Ydim = READLN( SETFILE )
  375.     OutFile = READLN( SETFILE )
  376.     FrmDelay = READLN( SETFILE )
  377.     DelOldFrms = READLN( SETFILE )
  378.     IQScale = READLN( SETFILE )
  379.     PQScale = READLN( SETFILE )
  380.     BQScale = READLN( SETFILE )
  381.     PATTERN = READLN( SETFILE )
  382.  
  383.     CLOSE( SETFILE )
  384.  
  385.  
  386. RETURN 0
  387.  
  388.  
  389.  
  390. /* Setup some MPEG parameters and calc. the number of GOPS */
  391. /* Calculate a reasonable GOP size ( at least 3 frames ) */
  392.  
  393. CalcGOPS:
  394.  
  395.     GOP_SIZE = LENGTH(PATTERN)
  396.  
  397.     I = 0
  398.  
  399.     DO I = I + 1 UNTIL GOP_SIZE >= 0
  400.        GOP_SIZE = I * LENGTH(PATTERN)
  401.  
  402.     END
  403.  
  404.  
  405.     IF EndFrame <= StFrame
  406.       THEN DO
  407.         EndFrame = StFrame + 1
  408.         Call Request(300,100,"You need more frames than that!",,"OK",,)
  409.       END
  410.  
  411.     TOT_FRAMES = EndFrame - StFrame + 1
  412.     TOT_GOPS = TRUNC( TOT_FRAMES / GOP_SIZE )
  413.  
  414.     IF TOT_FRAMES // GOP_SIZE ~= 0 THEN
  415.          TOT_GOPS = TOT_GOPS + 1
  416.  
  417.  
  418.     IF TOT_GOPS == 0
  419.      THEN
  420.        DO
  421.          Call Request(300,100,"You need more frames than that!",,"OK",,)
  422.          /* SAY
  423.          SAY ' Hey you''ll need more frames than that!!!'
  424.          SAY
  425.          EXIT */
  426.        END
  427.  
  428. RETURN 0
  429.  
  430.  
  431.  
  432.  
  433. /* This function creates the .param file which contains the operational */
  434. /* parameters for the mpeg_encode program */
  435.  
  436. WriteParamFile:
  437.  
  438.     SAY 'Compiling mpeg_encode Parameter File...'
  439.     SAY
  440.  
  441.     OPEN( PARMFILE, Outfile || '.param', 'W' )
  442.  
  443.     WRITELN( PARMFILE , '# This parameter file created by Easy_MPEG.rexx' )
  444.     WRITELN( PARMFILE , '# An Arexx program by Scott Tribbey 1995' )
  445.  
  446.     WRITELN( PARMFILE , '' )
  447.     WRITELN( PARMFILE , '' )
  448.     WRITELN( PARMFILE , 'PATTERN   ' || PATTERN )
  449.     WRITELN( PARMFILE , 'OUTPUT    ' || InputDir || OutFile || '.mpg' )
  450.     WRITELN( PARMFILE , '' )
  451.     WRITELN( PARMFILE , 'BASE_FILE_FORMAT   PPM' )
  452.     WRITELN( PARMFILE , 'GOP_SIZE   ' GOP_SIZE )
  453.     WRITELN( PARMFILE , 'SLICES_PER_FRAME   1  ' )
  454.     WRITELN( PARMFILE , '' )
  455.     WRITELN( PARMFILE , 'PIXEL  HALF' )
  456.     WRITELN( PARMFILE , 'RANGE  10' )
  457.     WRITELN( PARMFILE , 'PSEARCH_ALG     LOGARITHMIC' )
  458.     WRITELN( PARMFILE , 'BSEARCH_ALG     CROSS2' )
  459.     WRITELN( PARMFILE , 'IQSCALE         'IQScale )
  460.     WRITELN( PARMFILE , 'PQSCALE         'PQScale )
  461.     WRITELN( PARMFILE , 'BQSCALE         'BQScale )
  462.     WRITELN( PARMFILE , '' )
  463.     WRITELN( PARMFILE , 'REFERENCE_FRAME ORIGINAL' )
  464.     WRITELN( PARMFILE , 'FORCE_ENCODE_LAST_FRAME' )
  465.     WRITELN( PARMFILE , '' )
  466.     WRITELN( PARMFILE , 'YUV_SIZE       '||Xdim||'x'||Ydim )
  467.     WRITELN( PARMFILE , 'INPUT_DIR       '||FileInDir )
  468.     WRITELN( PARMFILE , 'INPUT' )
  469.     WRITELN( PARMFILE , FrameName || '*' || '.ppm   ' '[' || ,
  470.                         StFrame || '-' || EndFrame || ']')
  471.     WRITELN( PARMFILE , 'END_INPUT' )
  472.     WRITELN( PARMFILE , 'INPUT_CONVERT  *' )
  473.  
  474.     CLOSE( PARMFILE )
  475.  
  476. RETURN 0
  477.  
  478.  
  479.  
  480. RunHost:
  481.  
  482.     if ~show('l', "rexxarplib.library") then do
  483.     check = addlib('rexxarplib.library',0,-30,0)
  484.     end
  485.  
  486.     if ~show('l', "rexxsupportlib.library") then do
  487.     check = addlib('rexxsupport.library',0,-30,0)
  488.     end
  489.  
  490.     ADDRESS COMMAND
  491.  
  492.     /* The following command is the only way to use the createhost() */
  493.     /* function without locking up the script */
  494.  
  495.     Call OPENPORT(MPEGPORT)
  496.  
  497.     'Run ' 'SYS:Rexxc/rx ''Call createhost(MPEGHOST, MPEGPORT,)'''
  498.  
  499.     Call delay(100)  /* delay to allow the host to get set up */
  500.  
  501.     idcmp = 'CLOSEWINDOW+GADGETDOWN+GADGETUP'
  502.     flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH'
  503.     call OpenWindow(MPEGHOST, 50, 50, 340, 200, idcmp, flags, "Easy_MPEG 1.04 Scott Tribbey 1995")
  504.  
  505.     call SetAPen(MPEGHOST,1)
  506.  
  507.     /* Now Add the gadgets */
  508.  
  509.     call AddGadget(MPEGHOST,120 ,15 ,00 ,FrameName ,"%l STRING %d %g",200 )
  510.     call AddGadget(MPEGHOST,120 ,30 ,01 ,InputDir ,"%l STRING %d %g",200 )
  511.     call AddGadget(MPEGHOST,120 ,45 ,02 ,StFrame ,"%l STRING %d %g",100 )
  512.     call AddGadget(MPEGHOST,120 ,60 ,03 ,EndFrame ,"%l STRING %d %g",100 )
  513.     call AddGadget(MPEGHOST,135 ,75 ,04 ,Xdim ,"%l STRING %d %g",40 )
  514.     call AddGadget(MPEGHOST,205 ,75 ,05 ,Ydim ,"%l STRING %d %g",40 )
  515.     call AddGadget(MPEGHOST,120 ,120 ,06 ,OutFile ,"%l STRING %d %g",200 )
  516.     call AddGadget(MPEGHOST,120 ,135 ,07 ,FrmDelay ,"%l STRING %d %g",40 )
  517.     call AddGadget(MPEGHOST,120 ,150 ,08,"Del. Old Frames" ,"%l STRING %d")
  518.     call AddGadget(MPEGHOST,252 ,170 ,09,"Start\Scanning" ,"%l STRING %d")
  519.     call AddGadget(MPEGHOST,120 ,170 ,10,"Quit\Program" ,"QUIT")
  520.     call AddGadget(MPEGHOST,244 ,45 ,11,"File\Requester" ,"%l STRING %d")
  521.     call AddGadget(MPEGHOST,135 ,90 ,12,IQScale ,"%l STRING %d %g",40 )
  522.     call AddGadget(MPEGHOST,205 ,90 ,13,PQScale ,"%l STRING %d %g",40 )
  523.     call AddGadget(MPEGHOST,275 ,90 ,14,BQScale ,"%l STRING %d %g",40 )
  524.     call AddGadget(MPEGHOST,120 ,105 ,15,PATTERN ,"%l STRING %d %g",200 )
  525.  
  526.  
  527.     /* Now Add the gadget labels */
  528.  
  529.     call Move(MPEGHOST,10,22)
  530.     call Text(MPEGHOST,"  Frame Name:")
  531.     call Move(MPEGHOST,10,37)
  532.     call Text(MPEGHOST,"   Input Dir:")
  533.     call Move(MPEGHOST,10,52)
  534.     call Text(MPEGHOST," Start Frame:")
  535.     call Move(MPEGHOST,10,67)
  536.     call Text(MPEGHOST,"   End Frame:")
  537.     call Move(MPEGHOST,10,82)
  538.     call Text(MPEGHOST,"  Resolution: X")
  539.     call Move(MPEGHOST,190,82)
  540.     call Text(MPEGHOST,"Y")
  541.  
  542.     call Move(MPEGHOST,10,97)
  543.     call Text(MPEGHOST,"Quant. Scale: I")
  544.     call Move(MPEGHOST,190,97)
  545.     call Text(MPEGHOST,"P")
  546.     call Move(MPEGHOST,260,97)
  547.     call Text(MPEGHOST,"B")
  548.     call Move(MPEGHOST,10,112)
  549.     call Text(MPEGHOST,"Frm. Pattern:")
  550.  
  551.     call Move(MPEGHOST,10,127)
  552.     call Text(MPEGHOST,"    Out File:")
  553.     call Move(MPEGHOST,10,142)
  554.     call Text(MPEGHOST,"   Dir. Scan:")
  555.     call Move(MPEGHOST,170,142)
  556.     call Text(MPEGHOST,"Sec.")
  557.  
  558.     CALL MessageLoop()
  559.  
  560.     call Exit(MPEGHOST)
  561.  
  562.     Call CLOSEPORT(MPEGPORT)
  563.  
  564.     IF QUIT = 1 THEN EXIT(0)
  565.  
  566.  
  567. RETURN 0
  568.  
  569.  
  570.  
  571.  
  572.  
  573. MessageLoop:
  574.  
  575.  
  576. /* MAIN message loop */
  577.  
  578. keep_going=1
  579. DO WHILE keep_going=1
  580.  
  581.  
  582. /* Wait for at least one message to arrive */
  583.  
  584.   t=WAITPKT(MPEGPORT)
  585.  
  586. /* process *ALL* the messages waiting at this port */
  587.  
  588.   DO ff=1
  589.     p=GETPKT(MPEGPORT)
  590.  
  591.  
  592. /* p=NULL means not more messages at this port.
  593.   This is the *ONLY* time you should leave this loop! */
  594.  
  595.     IF p='0000 0000'x THEN LEAVE ff    /* message port empty */
  596.  
  597. /* get the message from the the port packet */
  598.  
  599.     command=GETARG(p)
  600.  
  601.  
  602. /* REPLY() as soon as you can, as soon as you are through extracting
  603.    data from the packet with GETARG() */
  604.  
  605.     t=REPLY(p,0)
  606.  
  607.  
  608. /* Ignore any messages received after the CLOSEWINDOW */
  609.  
  610.     IF keep_going=0 THEN ITERATE ff
  611.  
  612.  
  613.  
  614. /* now we can see what the message contains, and act on it */
  615.  
  616.     PARSE VAR command arg1' 'arg2' 'arg3' 'arg4' '
  617.     SELECT
  618.       WHEN arg1='CLOSEWINDOW' | arg1 = 'QUIT' THEN
  619.         DO
  620.           keep_going=0
  621.           QUIT = 1
  622.         END
  623.  
  624.       WHEN arg1='GADGETUP' THEN
  625.         DO
  626.           SELECT
  627.           WHEN arg2='STRING' THEN
  628.             DO
  629.              SELECT
  630.                WHEN arg3 = 0  THEN FrameName = arg4
  631.                WHEN arg3 = 1  THEN
  632.                  DO
  633.                     InputDir = arg4
  634.                     Call GetFileInDir()
  635.                  END
  636.  
  637.                WHEN arg3 = 2  THEN StFrame = arg4
  638.                WHEN arg3 = 3  THEN EndFrame = arg4
  639.                WHEN arg3 = 4  THEN Xdim = arg4
  640.                WHEN arg3 = 5  THEN Ydim = arg4
  641.                WHEN arg3 = 6  THEN OutFile = arg4
  642.                WHEN arg3 = 7  THEN FrmDelay = arg4
  643.  
  644.                WHEN arg3 = 8  THEN
  645.                 IF DelOldFrms = 'YES' THEN
  646.                   DelOldFrms = 'NO'
  647.                 ELSE
  648.                   DelOldFrms = 'YES'
  649.  
  650.                WHEN arg3 = 9  THEN keep_going=0
  651.                WHEN arg3 = 10 THEN FrmDelay = arg4
  652.  
  653.  
  654.                WHEN arg3 = 11 THEN Call GetBaseFile()
  655.                WHEN arg3 = 12 THEN IQScale = arg4
  656.                WHEN arg3 = 13 THEN PQScale = arg4
  657.                WHEN arg3 = 14 THEN BQScale = arg4
  658.                WHEN arg3 = 15 THEN PATTERN = arg4
  659.  
  660.              OTHERWISE
  661.              END
  662.                 Call CalcGOPS()
  663.                 Call Stats()
  664.             END
  665.  
  666.           OTHERWISE
  667.           END
  668.  
  669.         END
  670.  
  671.  
  672.       OTHERWISE DO
  673.  
  674.         SAY 'arg1 'arg1
  675.         SAY 'arg2 'arg2
  676.         SAY 'arg3 'arg3
  677.  
  678.       END
  679.  
  680.     END
  681.  
  682.   END
  683. END
  684.  
  685.  
  686. RETURN 0
  687.  
  688.  
  689. /* This is where we use the ARP file requester to get the Base Filename */
  690.  
  691. GetBaseFile:
  692.  
  693.     FileName = GetFile(100,100,FileInDir,,,)
  694.  
  695.     IF FileName ~= '' THEN
  696.       DO
  697.         FrameName = FileName
  698.         Call GetFrameName()
  699.  
  700.         call RemoveGadget(MPEGHOST,00)
  701.         call RemoveGadget(MPEGHOST,01)
  702.  
  703.         call AddGadget(MPEGHOST,120 ,15 ,00 ,FrameName ,"%l STRING %d %g",200 )
  704.         call AddGadget(MPEGHOST,120 ,30 ,01 ,InputDir ,"%l STRING %d %g",200 )
  705.       END
  706.  
  707. RETURN 0
  708.